<?php


/**
* CakePHP Schema Plugin
* http://cake-schema-plugin.googlecode.com
*
* @package schema
* @subpackage schema.config.schema
* @author Ivan Chistyakov <zetruger@gmail.com>
* @version $Id: i18n_auto.php 119 2010-10-17 05:01:48Z zetruger@gmail.com $
* @link $HeadURL: http://cake-schema-plugin.googlecode.com/svn/trunk/config/schema/i18n_auto.php $
* @license MIT License (http://opensource.org/licenses/mit-license.php)
*/


class i18nAutoSchema extends CakeSchema {

var $name = 'i18nAuto';

var $i18n = array(
	'id' => array('type' => 'integer', 'null' => FALSE, 'default' => NULL, 'key' => 'primary'),
	'locale' => array('type' => 'string', 'null' => FALSE, 'length' => 6, 'key' => 'index'),
	'model' => array('type' => 'string', 'null' => FALSE, 'key' => 'index'),
	'foreign_key' => array('type' => 'integer', 'null' => FALSE, 'key' => 'index'),
	'field' => array('type' => 'string', 'null' => FALSE, 'key' => 'index'),
	'content' => array('type' => 'text', 'null' => TRUE, 'default' => NULL),
	'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1), 'locale' => array('column' => 'locale', 'unique' => 0), 'model' => array('column' => 'model', 'unique' => 0), 'row_id' => array('column' => 'foreign_key', 'unique' => 0), 'field' => array('column' => 'field', 'unique' => 0))
);

function __construct($options = array()) {
	parent::__construct($options);
	$schemaVars = get_class_vars('i18nAutoSchema');
	$this->tables['i18n'] = $schemaVars['i18n'];
	foreach (App::objects('model') as $modelClass) {
		if (App::import('Model', $modelClass)) {
			$modelVars = get_class_vars($modelClass);
			if (isset($modelVars['translateTable'])) {
				$this->tables[$modelVars['translateTable']] = $schemaVars['i18n'];
			} elseif (isset($modelVars['translateModel'])) {
				$this->tables[Inflector::tableize($modelVars['translateModel'])] = $schemaVars['i18n'];
			}
		}
	}
}

}


?>